
import request from '@/utils/request'
import { otherFiltersItem } from '@/utils'

/**
 * 查询基础信息
 * @param {string} id
 * @returns
 */
export function queryDetail(id) {
  return request({
    url: `/api/v1/autonomyDesign/${id}`,
    method: 'get'
  })
}
/**
 * 修改基础信息
 * @param {object} data
 * @returns
 */
export function saveData(data) {
  return request({
    url: '/api/v1/autonomyDesign/maintain',
    method: 'post',
    data
  })
}

/**
 * 发起异常
 * @param {Object} data
 * @returns
 */
export function saveException(data) {
  return request({
    url: `/api/v1/autonomyDesign/exception`,
    method: 'post',
    data
  })
}

/**
 * 分配设计师
 * @param {Object} data
 * @returns
 */
export function submitAllotDesginer(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/allotDesigner/${type}`,
    method: 'post',
    data
  })
}

/**
 * 外观回传
 * @param {Object} data
 * @returns
 */
export function submitFacadeBack(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/facadeBack/${type}`,
    method: 'post',
    data
  })
}
/**
 * 图纸确认
 * @param {Object} data
 * @returns
 */
export function submitDrawingConfirm(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/drawingConfirm/${type}`,
    method: 'post',
    data
  })
}
/**
 * 终版图纸上传
 * @param {Object} data
 * @returns
 */
export function submitLastDrawing(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/drawingUpload/${type}`,
    method: 'post',
    data
  })
}

/**
 * 分配专员
 * @param {Object} data
 * @returns
 */
export function submitTransDistribute(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/allotAttache/${type}`,
    method: 'post',
    data
  })
}

/**
 * CRM下单
 * @param {Object} data
 * @returns
 */
export function submitCrmOrder(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/changeOrder/${type}`,
    method: 'post',
    data
  })
}

/**
 * 根据工单流水号查询crm信息
 * @param {string} code
 * @returns
 */
export function queryCrmByCode(code) {
  const data = new FormData()
  data.append('pageFlag', false)
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('receiptNumber', code, '=')]))
  return request({
    url: `/api/v1/autonomyDesign/getCRMOrder`,
    method: 'post',
    data
  })
}
/**
 * 确图
 * @param {Object} data
 * @returns
 */
export function submitConfirmDrawing(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/confirmDrawing/${type}`,
    method: 'post',
    data
  })
}

/**
 * 窗帘下单
 * @param {Object} data
 * @returns
 */
export function submitCurtainOrder(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/curtainOrder/${type}`,
    method: 'post',
    data
  })
}
/**
 * 解锁
 * @param {Object} data
 * @returns
 */
export function submitUnLock(data, type) {
  return request({
    url: `/api/v1/autonomyDesign/unLock/${type}`,
    method: 'post',
    data
  })
}
/**
 * 订单查询保存
 * @param {Object} data
 * @returns
 */
export function saveOrderSearch(data) {
  return request({
    url: `/api/v1/autonomyDesign/crmUpdate`,
    method: 'post',
    data
  })
}
/**
 * 订单查询修改
 * @param {Object} data
 * @returns
 */
export function editOrderSearch(data) {
  return request({
    url: `/api/v1/autonomyDesignCrm`,
    method: 'put',
    data
  })
}

/**
 * 单号图纸上传
 * @param {Object} data
 * @returns
 */
export function saveOrderPicUpload(data, reqType) {
  return request({
    // url: 'api/v1/autonomyDesign/drawingUpload/0',
    url: `/api/v1/autonomyDesign/orderPicUpload/${reqType}`,
    method: 'post',
    data
  })
}

/**
 * 修改主数据
 * @param {*} data
 * @returns
 */
export function editPersonData(data) {
  return request({
    url: `/api/v1/autonomyDesign`,
    method: 'put',
    data
  })
}
/**
 * 根据所属模块获取文件列表
 * @returns
 */
export function postConfigAttachmentTemplate() {
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('belongModel', 'SELF_DESIGN', '=')]))
  return request({
    url: '/api/v1/configAttachmentTemplate/page',
    method: 'POST',
    data
  })
}

/**
 * 上传配图
 * @param {*} data
 * @returns
 */
export function saveUploadPicture(data) {
  return request({
    url: `/api/v1/autonomyDesign/uploadPicture`,
    method: 'post',
    data
  })
}

/**
 * 新建自主设计任务
 * @param {Object} data
 * @returns
 */
export function saveAutoTask(data) {
  return request({
    url: `/api/v1/autonomyDesign`,
    method: 'post',
    data
  })
}
